package com.ruoyi.web.controller.jimu.admin;


import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cms.navItem.domain.CmsNavItem;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jimu.domain.JmReport;
import com.ruoyi.jimu.service.IJmReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;


/**
 * 报表Controller
 *
 * @author linyang
 * @date 2025-08-15
 */
@RestController("AdminJmReportController")
@RequestMapping("/admin/jimu/report")
public class JmReportController extends BaseController {


    @Resource
    private IJmReportService jmReportService;

    /**
     * 查询报表列表
     */
    //@PreAuthorize("@ss.hasPermi('jimu:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(JmReport jmReport) {
        startPage();
        List<JmReport> list = jmReportService.selectJmReportList(jmReport);
        return getDataTable(list);
    }

    /**
     * 导出报表列表
     */
    //@PreAuthorize("@ss.hasPermi('jimu:report:export')")
    @Log(title = "报表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JmReport jmReport) {
        List<JmReport> list = jmReportService.selectJmReportList(jmReport);
        ExcelUtil<JmReport> util = new ExcelUtil<JmReport>(JmReport.class);
        util.exportExcel(response, list, "报表数据");
    }

    /**
     * 获取报表详细信息
     */
    //@PreAuthorize("@ss.hasPermi('jimu:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(jmReportService.selectJmReportById(id));
    }

    /**
     * 新增报表
     */
    //@PreAuthorize("@ss.hasPermi('jimu:report:add')")
    @Log(title = "报表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JmReport jmReport) {
        return toAjax(jmReportService.insertJmReport(jmReport));
    }

    /**
     * 修改报表
     */
    //@PreAuthorize("@ss.hasPermi('jimu:report:edit')")
    @Log(title = "报表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JmReport jmReport) {
        return toAjax(jmReportService.updateJmReport(jmReport));
    }

    /**
     * 删除报表
     */
    //@PreAuthorize("@ss.hasPermi('jimu:report:remove')")
    @Log(title = "报表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(jmReportService.deleteJmReportByIds(ids));
    }


    /**
     * 状态修改
     */
    //@PreAuthorize("@ss.hasPermi('system:role:edit')")
    //@Log(title = "角色管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody JmReport jmReport) {
        jmReport.setUpdateBy(getUsername());
        return toAjax(jmReportService.updateReportStatus(jmReport));
    }

}
